<template>
<div class="container">
        <header class="header">
            <ul>
                <li><a href="javascript:window.history.back();"><span class="icon">&#xe738;</span></a></li>
                <li>
                    <h1>房源预约</h1>
                </li>
                <li></li>
            </ul>
        </header>
        <div class="top">
            <img src="images/home1.png" class="fl">
            <div class="top-r fr">
                <h1>整租·包图软件园二期 1室1厅</h1>
                <h3>次卧A·15m2 西南</h3>
                <p>
                    <span>2000</span>
                    <span>元/月</span>
                    <span>服务费:130元</span>
                </p>
            </div>
            <div class="clear"></div>
        </div>
        <form action="" method="post" @submit.prevent="yuyue">
            <section>
                <h1>选择预约看房时间<input class="form-control" type="text" v-model="date" id="date-time" placeholder="请选择预约日期"></h1>
                <div id="time">

                </div>
                <h1>联系方式</h1>
                <div class="tel">
                    <input type="text" name="tel"  v-model="tel" maxlength="13" value="138 8888 8888" placeholder="请输入联系方式">
                    <span>更改联系方式</span>
                </div>
                <div class="username">
                    <input type="text" name="username" v-model="username"  maxlength="20" placeholder="请填写真实姓名">
                </div>
            </section>
            <footer>
                <button class="btn" type="submit">立即预约</button>
                <p>地址:包图省包图市国际采购中心包图地铁站B出口500米</p>
            </footer>
         </form>
    </div>
</template>

<script type="text/ecmascript-6">
import Rolldate from 'rolldate';
  export default {
    name:'appoint',
    data () {
      return {
          date: '',
          tel: '',
          username: ''
      }
    },
    computed:{

    },
    methods:{
        init(){
            new Rolldate({
                // el属性
                el: '#date-time',
                // confirm方法
                confirm: (date)=>{
                    console.log(date);  // 2020-07-07
                    if(new Date().getTime() > new Date(date).getTime()){
                   

                        this.$alert('预约时间不能小于当前时间',{
                            title: '提示'
                        });
                        return false;
                    }

                    // 给变量date赋值
                    this.date = date;
                }
            });
        },
        yuyue(){
           // 验证
            if(this.date.length===0){
                this.$toast('请选择预约日期',{
                    duration: '1500',
                    position: 'bottom'
                });
                return;
            }
            if(!/^1[3456789]\d{9}$/.test(this.tel)){
                this.$toast('联系方式不正确',{
                    duration: '1500',
                    position: 'bottom'
                });
                return;
            }
            if(this.username.length===0){
                this.$toast('请输入真实姓名',{
                    duration: '1500',
                    position: 'bottom'
                });
                return;
            }

            // 模拟：预约成功
            this.$toast('预约成功',{
                duration: '1500',
                position: 'bottom'
            });
            setTimeout(()=>{
                this.$router.push('/');	// 切换到首页
            },1500);

            // 提交数据
            /**
            this.$axios({
                method: 'post',
                url: 'abc.php', // 测试
                data:{
                    date: this.date,
                    tel: this.tel,
                    username: this.username
                },// json对象
				transformRequest: [function (data) {
                    // 这块能让数据是以表单的形式提交
                    let ret = '';
                    for (let it in data) {
                        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&';
                    }
                    return ret;
                }],
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                }
            }).then((res)=>{
                console.log(res);

            }).catch((error)=>{
                console.log(error);
            });
            **/
        }
    },
    components: {

    },
    // created、mounted、updated、destroyed
    mounted(){
        this.init();
    }
    
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

 .header {
    margin: .3rem .3rem 0;
    height: .5rem;
}

.header ul {
    display: flex;
    justify-content: space-between;
}

.header ul li {
    width: 2.25rem;
    height: .5rem;
}

.header ul li h1 {
    font-size: .48rem;
    text-align: center;
}

.header ul li span {
    font-size: .4rem;
    line-height: .6rem;
    display: block;
}

.top {
    margin: .39rem;
    box-sizing: border-box;
    padding: .38rem .38rem 0;
    -moz-box-shadow: 0 0 10px #f3f3f3;
    -webkit-box-shadow: 0 0 10px #f3f3f3;
    box-shadow: 0 0 10px #f3f3f3;
}

.top>img {
    width: 1.96rem;
    height: 1.48rem;
    display: block;
}

.top .top-r {
    width: 3.73rem;
}

.top .top-r h1 {
    font-size: .4rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top .top-r h3 {
    color: #adada9;
    font-size: .28rem;
}

.top .top-r p {
    /* margin-top: .2rem; */
    font-size: .26rem;
    color: #f98642;
}

.top .top-r p span:nth-child(1) {
    font-size: .36rem;
    font-weight: 600;
}

.top .top-r p span:nth-child(2) {
    font-size: .26rem;
}

.top .top-r p span:nth-child(3) {
    color: #aeaeab;
    float: right;
    position: relative;
    top: .08rem;
}

section {
    margin: 0 .35rem;
    margin-bottom: 2.3rem;
}

section h1 {
    margin: .2rem 0;
    font-weight: 600;
    font-size: .36rem;
}


/* input时间 */

.form-control {
    width: 50%;
    border: none;
    height: .4rem;
    font-size: .3rem;
    float: right;
    text-align: right;
}


/* 时间插件 */

.rolldate-container .fadeIn {
    -webkit-transform: none !important;
    transform: none !important;
}

.rolldate-container .rolldate-panel {
    position: initial !important;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4rem !important;
    z-index: 1000;
    background: #fff;
    -webkit-transition: all .3s ease-in-out;
    -o-transition: all .3s ease-in-out;
    transition: all .3s ease-in-out;
    -webkit-transform: none !important;
    transform: none !important;
}

.rolldate-container .rolldate-mask {
    position: initial !important;
    width: 0 !important;
    height: 0 !important;
}

#rolldate-year {
    display: none;
}

.rolldate-btn {
    display: none;
}

.rolldate-container header {
    display: none;
}


/* .rolldate-container .rolldate-wrapper li {
    height: .72rem !important;
} */


/* section .time {
    width: 100%;
    height: 3.6rem;
    font-size: .32rem;
    color: #d3d3d1;
}
section .time-l,
section .time-r{
    height: 3.6rem;
    overflow-y: auto;
}
section .time-l {
    width: 60%;
}

section .time-r {
    width: 40%;
    text-align: right;
}
section .time-l ul li, 
section .time-r ul li {
    width: 100%;
    height: 1.2rem;
    line-height: 1.2rem;
}

section .time-l ul li:nth-child(2), 
section .time-r ul li:nth-child(2) {
    color: #414140;
}
 */

section .tel {
    margin-top: .3rem;
    border-top: .01rem solid #f7f7f6;
    border-bottom: .01rem solid #f7f7f6;
    height: .94rem;
    line-height: 1.1rem;
}

section .tel input[type="text"] {
    border: none;
    outline: none;
    font-size: .32rem;
    padding-left: .22rem;
}

section .tel span {
    float: right;
    font-size: .28rem;
    color: #ff3b3d;
}

section .username {
    margin-top: .43rem;
    height: .88rem;
    background-color: #f8f8f8;
    font-size: .32rem;
    line-height: 1.1rem;
    color: #cfcfcf;
}

section .username input[type="text"] {
    border: none;
    outline: none;
    padding-left: .36rem;
    background: none;
    width: 100%;
}

footer {
    position: fixed;
    bottom: 0;
    height: 2rem;
    background-color: #fff;
    width: 100%;
    box-shadow: 0 0 .05rem #f6f6f6;
    max-width: 7.5rem;
    margin: 0 auto;
}

footer .btn {
    margin: .32rem auto 0;
    display: block;
    background-color: #ff3b3d;
    font-size: .34rem;
    height: 1rem;
    line-height: 1.1rem;
    outline: none;
    border-radius: 3.35rem;
    width: 90%;
    color: #fff;
    text-align: center;
}

footer p {
    margin-top: .16rem;
    font-size: .26rem;
    color: #afafac;
    text-align: center;
}
</style>
